package entity

import (
	"database/sql/driver"
	"encoding/json"
	"fmt"
	"github.com/jinzhu/gorm"
)

type Rms []uint

func (m Rms) Value() (driver.Value, error) {
	return json.Marshal(m)
}

func (m *Rms) Scan(value interface{}) error {
	bytes, ok := value.([]byte)
	if !ok {
		return fmt.Errorf("类型断言失败")
	}
	return json.Unmarshal(bytes, m)
}

// 群聊消息
type GroupMsg struct {
	gorm.Model
	SenderId   uint   `json:"sender_id"`
	GroupId    uint   `json:"group_id"`
	Content    string `json:"content"`
	ReadMember Rms    `json:"member_id" gorm:"type:json"`
	Type       int    `json:"type"`
}

func (GroupMsg) TableName() string {
	return "group_msg"
}
